import Vue from 'vue'
import Router from 'vue-router'

// 引入首页
import layout from '@/layout/layout'
// 默认首页面
import home from '@/layout/home'
// 登录页面
import login from '@/components/sys/login/login'
// 401页面
import page401 from '@/components/sys/error/401'
// 404页面
import page404 from '@/components/sys/error/404'

/* 引用vue路由模块，并赋值给变量Router */
const _import = require('./_import_' + process.env.NODE_ENV)

Vue.use(Router)

/**
 * 这里定义需要根据权限来设置的路由
 * requiresAuth：是否需要拦截权限（需要拦截权限，后台必须配置）
 * @type {Array}
 */
const asyncRouterMap = [
  {
    path: '/home',
    name: 'home',
    component: home,
    meta: {
      requiresAuth: true,
      title: '内容'
    }
  },
  {
    path: '/systemManage/orgManage',
    name: 'orgManage',
    component: _import('systemManage/orgManage/orgManage'),
    meta: {
      requiresAuth: true,
      title: '机构管理'
    }
  },
  {
    path: '/systemManage/personalCenter',
    name: 'personalCenter',
    component: _import('systemManage/personalCenter/personalCenter'),
    meta: {
      requiresAuth: true,
      title: '个人中心'
    }
  },
  {
    path: '/systemManage/userManage',
    name: 'userManage',
    component: _import('systemManage/userManage/userManage'),
    meta: {
      requiresAuth: true,
      title: '用户管理'
    }
  },
  {
    path: '/systemManage/logManage',
    name: 'logManage',
    component: _import('systemManage/logManage/logManage'),
    meta: {
      requiresAuth: true,
      title: '日志管理'
    }
  },
  {
    path: '/systemManage/roleManage',
    name: 'roleManage',
    component: _import('systemManage/roleManage/roleManage'),
    meta: {
      requiresAuth: true,
      title: '角色管理'
    }
  },
  {
    path: '/systemManage/dictManage',
    name: 'dictManage',
    component: _import('systemManage/dictManage/dictManage'),
    meta: {
      requiresAuth: true,
      title: '数据字典管理'
    }
  },
  {
    path: '/systemManage/paramManage',
    name: 'paramManage',
    component: _import('systemManage/paramManage/paramManage'),
    meta: {
      requiresAuth: true,
      title: '系统参数管理'
    }
  },
  {
    path: '/systemManage/dictDataManage',
    name: 'dictDataManage',
    component: _import('systemManage/dictManage/dictDataManage'),
    meta: {
      requiresAuth: true,
      title: '字典数据'
    }
  },
  {
    path: '/equipControl/hardwareManage',
    name: 'hardwareManage',
    component: _import('equipControl/hardwareManage/hardwareManage'),
    meta: {
      requiresAuth: true,
      title: '硬件信息管理'
    }
  },
  {
    path: '/equipControl/hardwareChangeManage',
    name: 'hardwareChangeManage',
    component: _import('equipControl/hardwareChangeManage/hardwareChangeManage'),
    meta: {
      requiresAuth: true,
      title: '硬件信息变更申请'
    }
  },
  {
    path: '/equipControl/hardwareExamineManage',
    name: 'hardwareExamineManage',
    component: _import('equipControl/hardwareExamineManage/hardwareExamineManage'),
    meta: {
      requiresAuth: true,
      title: '硬件信息审核'
    }
  },
  {
    path: '/equipControl/hardwareStatusManage',
    name: 'hardwareStatusManage',
    component: _import('equipControl/hardwareStatusManage/hardwareStatusManage'),
    meta: {
      requiresAuth: true,
      title: '硬件状态变更'
    }
  },
  {
    path: '/equipControl/softwareManage',
    name: 'softwareManage',
    component: _import('equipControl/softwareManage/softwareManage'),
    meta: {
      requiresAuth: true,
      title: '软件信息管理'
    }
  },
  {
    path: '/equipControl/softwareChangeManage',
    name: 'softwareChangeManage',
    component: _import('equipControl/softwareChangeManage/softwareChangeManage'),
    meta: {
      requiresAuth: true,
      title: '软件信息变更申请'
    }
  },
  {
    path: '/equipControl/softwareExamineManage',
    name: 'softwareExamineManage',
    component: _import('equipControl/softwareExamineManage/softwareExamineManage'),
    meta: {
      requiresAuth: true,
      title: '软件信息审核'
    }
  },
  {
    path: '/equipControl/softwareStatusManage',
    name: 'softwareStatusManage',
    component: _import('equipControl/softwareStatusManage/softwareStatusManage'),
    meta: {
      requiresAuth: true,
      title: '软件状态管理'
    }
  },
  {
    path: '/equipControl/deviceInfoQuery',
    name: 'deviceInfoQuery',
    component: _import('equipControl/deviceInfoManage/deviceInfoQuery'),
    meta: {
      requiresAuth: true,
      title: '设备信息查询'
    }
  },
  {
    path: '/equipControl/deviceInfoStatistics',
    name: 'deviceInfoStatistics',
    component: _import('equipControl/deviceInfoManage/deviceInfoStatistics'),
    meta: {
      requiresAuth: true,
      title: '设备信息统计'
    }
  },
  {
    path: '/fileManage/fileList',
    name: 'fileList',
    component: _import('fileManage/fileList'),
    meta: {
      requiresAuth: true,
      title: '体系文件管理'
    }
  },
  {
    path: '/fileManage/fileLookManage/fileLook',
    name: 'fileLook',
    component: _import('fileManage/fileLookManage/fileLook'),
    meta: {
      requiresAuth: true,
      title: '体系文件查询'
    }
  },
  {
    path: '/fileManage/fileSystem',
    name: 'fileSystem',
    component: _import('fileManage/fileSystem/fileSystem'),
    meta: {
      requiresAuth: true,
      title: '体系文件系统'
    }
  },
  {
    path: '/communicationManage/filequery',
    name: 'filequery',
    component: _import('communicationManage/filequery/filequery'),
    meta: {
      requiresAuth: true,
      title: '通讯文档发件箱'
    }
  },
  {
    path: '/communicationManage/receiveQuery',
    name: 'receiveQuery',
    component: _import('communicationManage/filequery/receiveQuery'),
    meta: {
      requiresAuth: true,
      title: '通讯文档收件箱'
    }
  },
  {
    path: '/communicationManage/notice',
    name: 'notice',
    component: _import('communicationManage/notice/notice'),
    meta: {
      requiresAuth: true,
      title: '发送通知'
    }
  },
  {
    path: '/communicationManage/messages',
    name: 'messages',
    component: _import('communicationManage/message/messages'),
    meta: {
      requiresAuth: true,
      title: '发送消息'
    }
  },
  {
    path: '/communicationManage/letters',
    name: 'letters',
    component: _import('communicationManage/letters/letters'),
    meta: {
      requiresAuth: true,
      title: '发送函件'
    }
  },
  {
    path: '/industryDynamicsManage/industryDynamics',
    name: 'industryDynamics',
    component: _import('industryDynamicsManage/industryDynamics/industryDynamics'),
    meta: {
      requiresAuth: true,
      title: '行业动态新闻管理'
    }
  },
  {
    path: '/industryDynamicsManage/industryView',
    name: 'industryView',
    component: _import('industryDynamicsManage/industryDynamics/industryView'),
    meta: {
      requiresAuth: true,
      title: '行业动态新闻查看'
    }
  },
  {
    path: '/docResearchFindingsManage/docResearchFindings',
    name: 'docResearchFindings',
    component: _import('docResearchFindingsManage/docResearchFindings'),
    meta: {
      requiresAuth: true,
      title: '课题成果文档'
    }
  },
  {
    path: '/docResearchFindingsManage/docResearchLookManage/docResearchLook',
    name: 'docResearchLook',
    component: _import('docResearchFindingsManage/docResearchLookManage/docResearchLook'),
    meta: {
      requiresAuth: true,
      title: '课题成果查询'
    }
  },
  {
    path: '/docPolicyDocument/policyDocument',
    name: 'policyDocument',
    component: _import('docPolicyDocumentManage/docPolicyDocument'),
    meta: {
      requiresAuth: true,
      title: '政策文档管理'
    }
  },
  {
    path: '/docPolicyDocumentManage/docPolicyDocumentLookManage/docPolicyDocumentLook',
    name: 'docPolicyDocumentLook',
    component: _import('docPolicyDocumentManage/docPolicyDocumentLookManage/docPolicyDocumentLook'),
    meta: {
      requiresAuth: true,
      title: '政策文档查询'
    }
  },
  {
    path: '/workWeeklyManage/workWeekly/weeklySendQuery',
    name: 'weeklySendQuery',
    component: _import('workWeeklyManage/workWeekly/weeklySendQuery'),
    meta: {
      requiresAuth: true,
      title: '周报发件箱'
    }
  },
  {
    path: '/workWeeklyManage/workWeekly/weeklyDraft',
    name: 'weeklyDraft',
    component: _import('workWeeklyManage/workWeekly/weeklyDraft'),
    meta: {
      requiresAuth: true,
      title: '周报草稿'
    }
  },
  {
    path: '/workWeekly/weeklyTemplate',
    name: 'weeklyTemplate',
    component: _import('workWeeklyManage/workWeekly/weeklyTemplate'),
    meta: {
      requiresAuth: true,
      title: '周报模板管理'
    }
  },
  {
    path: '/workWeeklyManage/workWeekly/draftEdit',
    name: 'draftEdit',
    component: _import('workWeeklyManage/workWeekly/draftEdit'),
    meta: {
      requiresAuth: true,
      title: '周报编辑'
    }
  },
  {
    path: '/workWeeklyManage/workWeekly/worklyReiQuery',
    name: 'worklyReiQuery',
    component: _import('workWeeklyManage/workWeekly/receiveQuery'),
    meta: {
      requiresAuth: true,
      title: '周报收件箱'
    }
  },
  {
    path: '/productiondataManage/productManage',
    name: 'productManage',
    component: _import('productiondataManage/productiondataManage/productManage'),
    meta: {
      requiresAuth: true,
      title: '生产数据管理'
    }
  },
  {
    path: '/productiondataManage/productView',
    name: 'productView',
    component: _import('productiondataManage/productiondataManage/productView'),
    meta: {
      requiresAuth: true,
      title: '生产数据查看'
    }
  },
  {
    path: '/processCenter/modelManage',
    name: 'processmodelManage',
    component: _import('processCenter/modelManage/processmodelManage'),
    meta: {
      requiresAuth: true,
      title: '流程模型管理'
    }
  },
  {
    path: '/processCenter/processManage',
    name: 'processManage',
    component: _import('processCenter/processManage/processManage'),
    meta: {
      requiresAuth: true,
      title: '流程管理'
    }
  },
  {
    path: '/processCenter/nocompleteWork',
    name: 'nocompleteWork',
    component: _import('processCenter/personWork/nocompleteWork'),
    meta: {
      requiresAuth: true,
      title: '待办任务'
    }
  },
  {
    path: '/processCenter/completeWork',
    name: 'completeWork',
    component: _import('processCenter/personWork/completeWork'),
    meta: {
      requiresAuth: true,
      title: '已办任务'
    }
  },
  {
    path: '/processCenter/instanceManage',
    name: 'instanceManage',
    component: _import('processCenter/instanceManage/instanceManage'),
    meta: {
      requiresAuth: true,
      title: '流程实例管理'
    }
  },
  // 文档查询统计
  {
    path: '/docQueryStatistics/docQyery',
    name: 'docQyeryManage',
    component: _import('docQueryStatistics/docQyery/docQyeryManage'),
    meta: {
      requiresAuth: true,
      title: '文档查询'
    }
  },
  {
    path: '/docQueryStatistics/docStatistics',
    name: 'docStatisticsManage',
    component: _import('docQueryStatistics/docStatistics/docStatisticsManage'),
    meta: {
      requiresAuth: true,
      title: '文档统计'
    }
  },
  {
    path: '/demo',
    name: 'demo',
    component: _import('demo/demoManage'),
    meta: {
      requiresAuth: true,
      title: '首页1'
    }
  }
]

// 首页
const homePage = {
  path: '/',
  name: '首页',
  component: layout,
  redirect: '/home',
  children: asyncRouterMap
}

/**
 * 路由结构
 */
const routers = [
  {
    path: '/login',
    component: login,
    meta: {
      requiresAuth: false
    }
  },
  homePage,
  {path: '/404', component: page404},
  {path: '/401', component: page401}
]

/**
 * 重写路由的push方法
 */
const routerPush = Router.prototype.push
Router.prototype.push = function push (location) {
  return routerPush.call(this, location).catch(error => error)
}

export default new Router({
  // mode: 'history',
  routes: routers,
  scrollBehavior (to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return {x: 0, y: 0}
    }
  }
})
